<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_3_1-1-手动实现一个简易的限流函数</title>
</head>

<body>


  <!--载入vue.js-->
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    点击一次，两秒后可获取时间
    <button @click="click">按钮</button>
  </div>

  <script>
    const App = {
      //组件的data方法
      data() {
        //返回对象
        return {
          throttle: false,
        };
      },

      //组件的方法
      methods: {
        //限流函数原理
        click() {
          if (!this.throttle) {
            console.log(Date());
          } else {
            return;
          }
          this.throttle = true;
          setTimeout(() => {
            this.throttle = false;
          }, 2000); //每隔2秒执行一次函数
        },
      },
    };

    Vue.createApp(App).mount("#Application");
  </script>
</body>

</html>